package com.example.myapplication.apter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.Config.TokenBean;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.ClassificationlistBean;
import com.example.myapplication.ShuJu.DemandsBean;
import com.example.myapplication.government.ClaimDdetailsActivity;
import com.example.myapplication.government.DemandsActivity;
import com.example.myapplication.government.NewRquestPageActivity;
import com.google.gson.Gson;

import java.util.List;

public class DemandApter extends  RecyclerView.Adapter<DemandApter.Myhot>{
    private Context context ;
    private View view;
    private List<DemandsBean.RowsBean> list;

    public DemandApter(Context context, List<DemandsBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public DemandApter.Myhot onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(context).inflate(R.layout.item_demand,null);
        return new DemandApter.Myhot(view);
    }

    @Override
    public void onBindViewHolder(@NonNull DemandApter.Myhot holder, int position) {
        holder.titleTextView.setText("标题:"+list.get(position).getTitle());
        holder.departmentTextView.setText("承办单位:"+list.get(position).getUndertaker());
        holder.submitTimeTextView.setText("提交时间:"+list.get(position).getCreateTime());
        if(list.get(position).getState().equals("0")){
            holder.statusTextView.setText("未处理");
        }else {
            holder.statusTextView.setText("已处理");
        }
        //诉求详情
        holder.Claimdetailsutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, ClaimDdetailsActivity.class);
                intent.putExtra("DemandApterID",String.valueOf(list.get(position).getId()));
                context.startActivity(intent);
            }
        });
        holder.li_demand.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, ClaimDdetailsActivity.class);
                intent.putExtra("DemandApterID",String.valueOf(list.get(position).getId()));
                context.startActivity(intent);
            }
        });
        //点击进入新建诉求页
       /* holder.publishButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, NewRquestPageActivity.class);
                intent.putExtra("DemandApterID",String.valueOf(list.get(position).getId()));
                context.startActivity(intent);
            }
        });*/
    }

    @Override
    public int getItemCount() {
        return list==null?0:list.size();
    }

    class Myhot extends RecyclerView.ViewHolder{

        private final TextView titleTextView;
        private final TextView departmentTextView;
        private final TextView submitTimeTextView;
        private final TextView statusTextView;
        private final Button Claimdetailsutton;
        private final LinearLayout  li_demand;

        public Myhot(@NonNull View itemView) {
            super(itemView);
            titleTextView = itemView.findViewById(R.id.titleTextView);
            departmentTextView = itemView.findViewById(R.id.departmentTextView);
            submitTimeTextView = itemView.findViewById(R.id.submitTimeTextView);
            statusTextView = itemView.findViewById(R.id.statusTextView);
            Claimdetailsutton = itemView.findViewById(R.id.Claimdetailsutton);
            li_demand = itemView.findViewById(R.id.li_demand);
        }
    }
}

